{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}
var
	a:array[1..101,1..101] of longint;
	t,sum:longint;
	n,m,i,j,maxi:integer;
begin
	readln(n,m);
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			read(t);
			a[i][j]:=t;
			if(j=1)then
			begin
				sum:=t;
				maxi:=1;
			end
			else
			begin
				sum:=sum+t;
				if(t>a[i][maxi])then
					maxi:=j;
			end;
		end;
		a[i][maxi]:=sum;
	end;
	for i:=1 to n do
	begin
		for j:=1 to m do
		begin
			write(a[i][j],' ');
		end;
		writeln;
	end;
end.
